﻿using HCQ2_IBLL;
using HCQ2_Model.APIBase;
using HCQ2_Model.VR;
using HCQ2_Model.VRDD.InputDto._20220625;
using HCQ2_Model.VRDD.InputDto._20220704;
using HCQ2_Model.VRDD.InputDto._211217;
using HCQ2_Model.VRDD.OutputDto._20220625;
using HCQ2_Model.VRDD.OutputDto._20220704;
using HCQ2_Model.VRDD.OutputDto._211217;
using HCQ2_Model.VRQDMeta.InputDto._20220418;
using HCQ2_Model.VRQDMeta.OutputDto._20220418;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;

namespace HCQ2_BLL
{
    public partial class T_VRStayUserLogBLL : IT_VRStayUserLogBLL
    {
        /// <summary>
        ///  获取楼宇入住日志
        /// </summary>
        /// <param name="file_id"></param>
        /// <param name="page"></param>
        /// <param name="rows"></param>
        /// <returns></returns>
        public List<OutputBuildLog> GetBuildLogList(int file_id, int page, int rows, out int total)
        {
            return DBSession.IT_VRStayUserLogDAL.GetBuildLogList(file_id, page, rows, out total);
        }
        /// <summary>
        ///  添加入住日志返回数据
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public OutputSaveHouse GetBuildData(InputSaveHouse param)
        {
            var file = DBSession.IT_VRStayUserLogDAL.GetBuildData(param);
            if (file == null)
                return null;
            file.folderList = DBSession.IT_VRStayUserLogDAL.GetUserFloderInfo(file.folderID);
            file.folderList?.ForEach(o =>
            {
                if (!string.IsNullOrEmpty(o.folderImage))
                    o.folderImage = o.folderImage.Replace("~", HttpContext.Current.Request.Url.AbsoluteUri.Substring(0, HttpContext.Current.Request.Url.AbsoluteUri.IndexOf("/api/")));
            });
            return file;
        }
        /// <summary>
        ///  获取房屋信息
        /// </summary>
        /// <param name="param"></param>
        /// <param name="user_id"></param>
        /// <returns></returns>
        public OutputHouseInfo GetHouseInfo(InputHouseInfo param, int user_id)
        {
            OutputHouseInfo obj = new OutputHouseInfo();
            //统计已入住用户数
            int ownerHouseTotal = DBSession.IT_VRStayUserLogDAL.GetHouseSum(param);
            //获取楼层明细
            var floorList = DBSession.IT_VRStayUserLogDAL.GetFloorDetialList(param);
            //获取商品明细
            var fileList = DBSession.IT_VRStayUserLogDAL.GetFileDetialList(param, user_id);
            //获取楼房图片明细
            var ImageList = DBSession.IT_VRStayUserLogDAL.GetImageDetial(param);
            fileList?.ForEach(o =>
            {
                //头像地址
                if (!string.IsNullOrEmpty(o.fileImage))
                    o.fileImage = o.fileImage.Replace("~", HttpContext.Current.Request.Url.AbsoluteUri.Substring(0, HttpContext.Current.Request.Url.AbsoluteUri.IndexOf("/api/")));
                if (!string.IsNullOrEmpty(o.ownerUserImage))
                    o.ownerUserImage = o.ownerUserImage.Replace("~", HttpContext.Current.Request.Url.AbsoluteUri.Substring(0, HttpContext.Current.Request.Url.AbsoluteUri.IndexOf("/api/")));
                //真实姓名设置
                if (!string.IsNullOrEmpty(o.userid) && !o.userid.Equals(param.userID) && o.hide_name != 2 && o.friend <= 0)
                    o.ownerRealName = string.Empty;
            });
            ImageList?.ForEach(o =>
            {
                if (!string.IsNullOrEmpty(o.imageUrl))
                    o.imageUrl = o.imageUrl.Replace("~", HttpContext.Current.Request.Url.AbsoluteUri.Substring(0, HttpContext.Current.Request.Url.AbsoluteUri.IndexOf("/api/")));
            });
            obj.fileList = fileList;
            obj.floorList = floorList;
            obj.ownerHouseTotal = ownerHouseTotal;
            obj.ImageList = ImageList;
            return obj;
        }
        /// <summary>
        ///  获取房屋图片信息
        /// </summary>
        /// <param name="param"></param>
        /// <param name="user_id"></param>
        /// <returns></returns>
        public HouseImageDetial GetHouseImages(InputHouseInfo param, int user_id)
        {
            HouseImageDetial obj = new HouseImageDetial();
            //统计已入住用户数
            int ownerHouseTotal = DBSession.IT_VRStayUserLogDAL.GetHouseSum(param);
            //获取楼层明细
            var floorList = DBSession.IT_VRStayUserLogDAL.GetFloorDetialList(param);
            //获取商品明细
            var fileList = DBSession.IT_VRStayUserLogDAL.GetFileDetialList(param, user_id);
            //获取楼房图片明细
            var ImageList = DBSession.IT_VRStayUserLogDAL.GetImageDetial(param);
            fileList?.ForEach(o =>
            {
                //头像地址
                if (!string.IsNullOrEmpty(o.fileImage))
                    o.fileImage = o.fileImage.Replace("~", HttpContext.Current.Request.Url.AbsoluteUri.Substring(0, HttpContext.Current.Request.Url.AbsoluteUri.IndexOf("/api/")));
                //真实姓名设置
                if (!string.IsNullOrEmpty(o.userid) && !o.userid.Equals(param.userID) && o.hide_name != 2 && o.friend <= 0)
                    o.ownerRealName = string.Empty;
            });
            ImageList?.ForEach(o =>
            {
                if (!string.IsNullOrEmpty(o.imageUrl))
                    o.imageUrl = o.imageUrl.Replace("~", HttpContext.Current.Request.Url.AbsoluteUri.Substring(0, HttpContext.Current.Request.Url.AbsoluteUri.IndexOf("/api/")));
            });
            obj.fileList = fileList;
            obj.floorList = floorList;
            obj.ImageList = ImageList;
            obj.ownerHouseTotal = ownerHouseTotal;
            return obj;
        }
        /// <summary>
        ///  获取用户的入住信息
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public OutputUserHouseInfo GetUserHouseInfo(BaseVRAPI param)
        {
            OutputUserHouseInfo file = DBSession.IT_VRStayUserLogDAL.GetUserHouseInfo(param);
            if (file == null)
                return null;
            file.floorList = DBSession.IT_VRStayUserLogDAL.GetUserFloderInfo(file.folderID);
            return file;
        }
        /// <summary>
        ///  获取用户住宅列表
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public BasePage<OutputUserHouse> GetUserHouseList(InputUserHouse param)
        {
            BasePage<OutputUserHouse> result = new BasePage<OutputUserHouse>();
            int total;
            var list = DBSession.IT_VRStayUserLogDAL.GetUserHouseList(param, out total);
            list?.ForEach(s =>
            {
                if (s.stayType == 0)
                {
                    s.selfImage = null;
                    s.coverImage = null;
                }
                //商品横向缩略图
                if (!string.IsNullOrEmpty(s.fileImage))
                    s.fileImage = s.fileImage.Replace("~", HttpContext.Current.Request.Url.AbsoluteUri.Substring(0, HttpContext.Current.Request.Url.AbsoluteUri.IndexOf("/api/")));
                //获取所属目录及父目录列表
                s.folderList = DBSession.IT_VRStayUserLogDAL.GetFloderAndParent(s.folderId);
                s.folderList?.ForEach(o =>
                {
                    if (!string.IsNullOrEmpty(o.folderImage))
                        o.folderImage = o.folderImage.Replace("~", HttpContext.Current.Request.Url.AbsoluteUri.Substring(0, HttpContext.Current.Request.Url.AbsoluteUri.IndexOf("/api/")));
                });
            });
            result.total = total;
            result.rows = list;
            return result;
        }
        /// <summary>
        /// 获取用户住宅详情
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public OutputGetUserHouseDetail GetUserHouseDetail(InputGetUserHouseDetail param)
        {
            OutputGetUserHouseDetail houseDetail = DBSession.IT_VRStayUserLogDAL.GetUserHouseDetail(param);
            if (houseDetail != null)
            {
                if (houseDetail.stayType == 0)
                {
                    houseDetail.aliasName = null;
                    houseDetail.selfImage = null;
                }
                houseDetail.folderList = DBSession.IT_VRStayUserLogDAL.GetFloderAndParent(houseDetail.folderId);
            }
            return houseDetail;
        }
        public OutputGetHouseDetail GetHouseDetail(InputGetHouseDetail param)
        {
            OutputGetHouseDetail list = DBSession.IT_VRStayUserLogDAL.GetHouseDetail(param);
            if (list != null)
            {
                if (!string.IsNullOrEmpty(list.coverImage))
                    list.coverImage = list.coverImage.Replace("~", HttpContext.Current.Request.Url.AbsoluteUri.Substring(0, HttpContext.Current.Request.Url.AbsoluteUri.IndexOf("/api/")));
                if (!string.IsNullOrEmpty(list.fileImage))
                    list.fileImage = list.fileImage.Replace("~", HttpContext.Current.Request.Url.AbsoluteUri.Substring(0, HttpContext.Current.Request.Url.AbsoluteUri.IndexOf("/api/")));
                if (!string.IsNullOrEmpty(list.ownerUserImage))
                    list.ownerUserImage = list.ownerUserImage.Replace("~", HttpContext.Current.Request.Url.AbsoluteUri.Substring(0, HttpContext.Current.Request.Url.AbsoluteUri.IndexOf("/api/")));
                list.stayList = stayList(param.fileID);
                if (list.stayList.Count > 0)
                {
                    list.stayList.ForEach(o =>
                    {
                        if (!string.IsNullOrEmpty(o.userImage))
                            o.userImage = o.userImage.Replace("~", HttpContext.Current.Request.Url.AbsoluteUri.Substring(0, HttpContext.Current.Request.Url.AbsoluteUri.IndexOf("/api/")));
                    });
                }
                list.folderList = DBSession.IT_VRStayUserLogDAL.GetFloderAndParent(list.folderID);
                if (list.folderList.Count > 0)
                {
                    list.folderList.ForEach(o =>
                    {
                        if (!string.IsNullOrEmpty(o.folderImage))
                            o.folderImage = o.folderImage.Replace("~", HttpContext.Current.Request.Url.AbsoluteUri.Substring(0, HttpContext.Current.Request.Url.AbsoluteUri.IndexOf("/api/")));
                    });
                }
            }
            return list;
        }
        public List<stays> stayList(int fileID)
        {
            List<stays> list = DBSession.IT_VRStayUserLogDAL.stayList(fileID);
            return list;
        }
    }
}